package com.googlecode.wannabet.controller.ui;

import java.util.Date;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.googlecode.wannabet.domain.Match;
import com.googlecode.wannabet.domain.Tournament;
import com.googlecode.wannabet.domain.Venue;

public class CreateTournamentController extends Controller {

	@Override
	protected Navigation run() throws Exception {
		String submit = asString("submit");
		if(!"true".equals(submit)) {
			return forward("/jsps/createTournament.jsp");
		}
		
		Long id = asLong("tournamentID");
		String name = asString("name");

		Entity venue = Tournament.getTournamentEntity(id, name);
		
		DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
		datastore.put(venue);
		
		return redirect("/ui/");
	}

}
